﻿
namespace Auros.Categorisation.Umbraco
{
    using System;
    using System.Web.UI.WebControls;
    using umbraco.cms.businesslogic.datatype;
    using umbraco.interfaces;

    public abstract class PreValueEditorBase : WebControl, IDataPrevalue
    {
        protected readonly umbraco.cms.businesslogic.datatype.BaseDataType DataType;

        public PreValueEditorBase(umbraco.cms.businesslogic.datatype.BaseDataType dataType)
        {
            this.DataType = dataType;
        }

        public abstract System.Web.UI.Control Editor { get; }

        public abstract void Save();

        protected abstract void RenderPreValueProperties(System.Web.UI.HtmlTextWriter writer);

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            this.EnsureChildControls();

            this.RegisterEmbeddedClientResource(typeof(PreValueEditorBase), "Auros.Categorisation.Resources.DataTypePreValueEditor.css", ClientDependencyType.Css);
        }

        protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)
        {
            writer.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Class, "auros-datatype");
            writer.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);

            this.RenderPreValueProperties(writer);

            writer.RenderEndTag();
        }
    }
}